# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=packaging
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=19.2
pkgrel=1
pkgdesc="Core utilities for Python packages (mingw-w64)"
arch=('any')
url="https://github.com/pypa/packaging"
license=('Apache')
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools" "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-pyparsing" "${MINGW_PACKAGE_PREFIX}-python2-pyparsing")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python3-pytest-runner" "${MINGW_PACKAGE_PREFIX}-python2-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python3-pretend" "${MINGW_PACKAGE_PREFIX}-python2-pretend" 
              "${MINGW_PACKAGE_PREFIX}-python3-coverage" "${MINGW_PACKAGE_PREFIX}-python2-coverage")
source=(https://pypi.io/packages/source/p/packaging/${_realname}-${pkgver}.tar.gz)
sha256sums=('28b924174df7a2fa32c1953825ff29c61e2f5e082343165438812f00d3a7fc47')

prepare() {  
  cd "${srcdir}"
  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done
}

# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.
build() {
  for pver in {2,3}; do
    msg "Python ${pver} build for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

check() {
  for pver in {2,3}; do  
    msg "Python ${pver} test for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py ptr
  done
}

package_python3-packaging() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-pyparsing"
           "${MINGW_PACKAGE_PREFIX}-python3-six"
           "${MINGW_PACKAGE_PREFIX}-python3-attrs")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/COPYING"
}

package_python2-packaging() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-pyparsing"
           "${MINGW_PACKAGE_PREFIX}-python2-six"
           "${MINGW_PACKAGE_PREFIX}-python2-attrs")

  cd "${srcdir}/python2-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/COPYING"
}

package_mingw-w64-i686-python2-packaging() {
  package_python2-packaging
}

package_mingw-w64-i686-python3-packaging() {
  package_python3-packaging
}

package_mingw-w64-x86_64-python2-packaging() {
  package_python2-packaging
}

package_mingw-w64-x86_64-python3-packaging() {
  package_python3-packaging
}
